package com.woniu.controller;

import com.woniu.entity.utils.ResponseEntity;
import com.woniu.service.OrderService;
import com.woniu.service.OrderServiceByProduct;
import com.woniuxy.annotations.RequirePerm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@RefreshScope//只要有这个注解的类，里面的配置信息，就支持热刷新
public class OrderController {
    @Value("${woniu.config}")
    private String myConfig;
    @Autowired
    OrderService orderService;
    @Autowired
    OrderServiceByProduct orderServiceByProduct;
    @GetMapping("/{pid}/{num}")
    @RequirePerm(perms = {"order::add","order::edit"})
    public ResponseEntity generateOrder(@PathVariable Integer pid, @PathVariable Integer num){
        return orderService.generateOrder(pid, num);
    }
    @GetMapping("/{name}/{minPrice}/{maxPrice}")
    public ResponseEntity findProductList(@PathVariable String name,@PathVariable double minPrice,@PathVariable double maxPrice){
        return orderServiceByProduct.findProductList(name,minPrice,maxPrice);
    }
    @GetMapping("/showConfig")
    public ResponseEntity showConfig(){
        return new ResponseEntity(myConfig);
    }
}
